﻿/***************************************************************************
 * 文 件 名:   HK_FollowTargetItem
 * 
 * 描    述:   Camera多目标切换管理工具，HK_FollowTargetItem 控制脚本
 * 
 * 版    本：  V1.1
 * 创 建 者：  京产肠饭、谭潇杰
 * 创建时间：  2023/5/9
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
****************************************************************************/

using UnityEngine;

namespace HKTools
{
    public class HK_FollowTargetItem : HK_BaseTargetItem
    {
        public Vector3 targetPos
        {
            get { return transform.position + transform.forward * targetDis; }
        }

        public Vector3 targetDir
        {
            get { return transform.position - targetPos; }
        }

        [Header("位置标记的半径：")]
        public float targetRadius = 1f;

        [Header("默认距离（Green）：")]
        public float targetDis = 2;
        [Header("最近距离（Blue）：")]
        public float minDis;
        [Header("最远距离（Red）：")]
        public float maxDis;

        // 绿色为默认目标位置，红色为最远位置，蓝色为最近位置
        void OnDrawGizmosSelected()
        {
            if (minDis > targetDis)
                minDis = targetDis;

            Gizmos.color = Color.blue;
            Gizmos.DrawRay(transform.position, transform.forward * minDis);
            Gizmos.DrawSphere(transform.position + transform.forward * minDis, targetRadius);

            Gizmos.color = Color.green;
            Gizmos.DrawRay(transform.position + transform.forward * minDis, transform.forward * (targetDis - minDis));
            Gizmos.DrawSphere(transform.position + transform.forward * targetDis, targetRadius);

            if (maxDis < targetDis)
                maxDis = targetDis;

            Gizmos.color = Color.red;
            Gizmos.DrawRay(transform.position + transform.forward * targetDis, transform.forward * (maxDis - targetDis));
            Gizmos.DrawSphere(transform.position + transform.forward * maxDis, targetRadius);
        }
    }
}